package app.netant.book.ajman;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
import app.netant.book.base.BaseEntity;
import app.netant.book.base.BasePage;
import cn.lily.com.enviroment.Enviroment;

public class AjmanPage extends BasePage {

	public AjmanPage(String netSite) {
		super(netSite);
		this.tableKey = "ajman";
		this.selectKey = "#main .lists .book";
		this.preHref = "http://www.ajman.cc";
	}

	@Override
	public String buildHref(Element element) {		
		
		String id = element.attr("id");
		
		id = id.substring(5);
		
		String href = "http://www.ajman.cc/txt/xiazai"+id+".html";
		
		return href;
	}

	@Override
	public BaseEntity buildEntity() {
		return new AjmanEntity();
	}

	@Override
	public BaseDetail buildDetail(String href) {
		return new AjmanDetail(href);
	}

	@Override
	public void afterEntity(BaseEntity entity, Element element) {
		
		String title = element.select(".book_info h2 a").text();
		Elements wEles = element.select(".book_info p");
		for(int i=0;i<wEles.size();i++){
			
			String writer = wEles.get(i).text().trim();
			if(writer.startsWith("作者")){
				int idx = writer.indexOf("：");
				if(idx>0){
					writer = writer.substring(idx+1).trim();
					entity.setNovelWriter(writer);
				}
				
			}
			
		}
		
		
		
		entity.setNovelName(title);
		entity.setNovelFullName(title+".txt");
		
	}
	
	public static void main(String[] args) {
		Enviroment.createEnv();
		Enviroment.getEnv().getLogBean().beginLog();
		AjmanPage page = new AjmanPage("https://www.3uww.cc/soft1/");
		page.analyseHref();
	}
	
}
